package pers.course.test;

import org.w3c.dom.ls.LSOutput;

class A {
    public A() {
        System.out.println("Constructed an instance of A");
    }
    @Override
    public String toString() {
        return "This is A";
    }
}

class B extends A{
    public B() {
        System.out.println("Constructed an instance of B");
    }
    @Override
    public String toString() {
        return "This is B";
    }
}

class C extends B{
    public C() {
        System.out.println("Constructed an instance of C");
    }
    @Override
    public String toString() {
        return "This is C";
    }
}

public class ABC {
    public static void main(String[] args) {
        A a1 = new C();
        System.out.println(a1);
        B b1 = (B)a1;
        System.out.println(b1);
        C c1 = (C)b1;
        System.out.println(c1);
        /**
        Constructed an instance of A
        Constructed an instance of B
        Constructed an instance of C
        This is C
        This is C
        This is C
         **/

        A a2 = new B();
        System.out.println(a2);
        B b2 = (B)a2;
        // C c2 = (C)a2;
    }
}
